<template>
	<view style="background-color: #fff;">
		<view style="display: flex;justify-content: space-around;height: 230upx;">
			<view style="margin-top: 30upx;">
				<image style="width: 170upx;height: 150upx;" src="../../../static/zczlogo.png" mode=""></image>
			</view>
			<view style="height: 200upx;">
				<view style="margin-top: 55upx;">
					当时算力 <text style="color: #D5832D;margin-left: 15upx;"> {{wheel}}轮</text>
				</view>
				<view style="font-size: 32upx;color: #D5832D;font-weight: 600;text-align: center;">
					{{zichan_power}}
				</view>
			</view>
			<view style="height: 200upx;">
				<view style="margin-top: 30upx;" @click="obtain">
					<text>待释放易豆值</text><text style="margin-left: 20upx;"> > </text>
					<view>{{bz}}</view>
				</view>
				<view @click="tozczdh">
					<text>已释放易豆值 </text><text style="margin-left: 20upx;"> > </text>
					<view>{{bz_release}}</view>
				</view>
			</view>
		</view>
		<view style="height: 450upx;color: #B81738;">
			<view class="qiun-columns">
				<canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchstart="touchLineA"></canvas>
			</view>
		</view>
		<view class="container" style="margin-top: 80upx;">
			<!-- <view class="all_add">累计奖励 + {{topres}} 元</view> -->
			<!-- 带上拉加载的数据列表 -->
			<view class="big-loading-text loading-text" style="height: 80upx;line-height: 80upx;">
				<text>信息展示</text>
				<text>数量</text>
				<text>当时算力</text>
				<text>当时总量</text>
				<!-- <text>来源</text> -->
			</view>
			<!-- 数据列表 -->
			<scroll-view scroll-y="true" style="height: 300upx;">
				<view class="loading-text" v-for="(value,key) in list" :key="key" style="height: 50upx;line-height: 50upx;">
					<text>兑换算力</text>
					<text>{{value.num}}</text>
					<text>{{value.price}}</text>
					<text>{{value.now_num}}</text>
				</view>
			</scroll-view>
		</view>
		<view style="display: flex;background-color: #fff;width: 100%;padding-top: 5px;position: fixed;bottom: 5upx;height: 100upx;background-color: #05052B;color: #fff;justify-content: space-around;">
			<view style="display: flex;flex-direction: column;" @click="getbuy">
				<image style="width: 50upx;height: 50upx;" src="../../../static/goumai.png" mode=""></image>
				<view>
					购买
				</view>
			</view>
			<view style="display: flex;flex-direction: column;" @click="togetbuy">
				<image style="width: 50upx;height: 50upx;margin-left: 30upx;" src="../../../static/duihuan.png" mode=""></image>
				<view>
					兑换易豆
				</view>
			</view>
			<view style="display: flex;flex-direction: column;" @click="getsale">
				<image style="width: 50upx;height: 50upx;" src="../../../static/guamai.png" mode=""></image>
				<view>
					挂卖
				</view>
			</view>
		</view>
	</view>
</template>

<script> 
import uniLoadMore from '../../../components/uni-load-more.vue';
import uCharts from '@/components/u-charts/u-charts.js';
	// import  { isJSON } from '@/common/checker.js';
	var _self;
	var canvaLineA=null;
	export default {
		components: {
			uniLoadMore,
			// uCharts,
			// canvas
		},
		data() {
			return {
				cWidth:'',
				cHeight:'',
				pixelRatio:1,
				textarea:'',
				itemCount:6,//x轴单屏数据密度
				sliderMax:50,
				s_exchange:'',
				list:[],
				wheel:'',
				zichan_power:'',
				nzichan_power:'',
				bz:'',
				bz_release:'',
				res:[],
				openid:'',
				systemInfo:[],
				active:"active",
				index:1,
				topres:1,
				newsList:[],
				loadingText: '加载中...',
				loadingType: 0,
				contentText: {
					contentdown: '上拉显示更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				load: 0,
				page: 1,
				timer:{},
				// option:{
				// 	xAxis: [1592459758000,1592459858000,1592459958000,1592460058000],
				// 	yAxis: {},
				// 	data: [
				// 				{
				// 						title: '上证指数',
				// 						isBg: true,
				// 						data:[1,20,30,40],
				// 				}
								
				// 	],
				// 	dataLineXColor: ['#E70012', '#49A6E9']
				// },
			}
		},
		onLoad: function(e) {
			// uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.getassets()
					this.getassets1()
					this.getnewsList()
					//页面一加载时请求一次数据`
					// uni.hideLoading()
				},
				fail: () => {
					uni.navigateTo({
						url: '../login/login'
					});
				}
			});
			_self = this;
			//#ifdef MP-ALIPAY
			uni.getSystemInfo({
				success: function (res) {
					if(res.pixelRatio>1){
						//正常这里给2就行，如果pixelRatio=3性能会降低一点
						//_self.pixelRatio =res.pixelRatio;
						_self.pixelRatio =2;
					}
				}
			});
			//#endif
			this.cWidth=uni.upx2px(750);
			this.cHeight=uni.upx2px(500);
			this.getServerData();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getnewsList()
		},
		// 上拉加载
		onReachBottom(){
			if (this.timer != null) {
				clearTimeout(this.timer)
			}
			this.timer = setTimeout(()=> {
				this.getmorenews()
			}, 1000);
		},
		onReady() {
			
		},
		methods: {
			getServerData(){
				uni.request({
					url: 'http://mall.zhongzhengyicai.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=tzz.k_data&app=1',
					data:{
					},
					success: function(res) {
						console.log(res.data)
						let LineA = {categories:[],series:[]};
						
						// LineA.categories= res.data.xAxis;
						LineA.categories= ['五天前','四天前','三天前','两天前','一天前'];
						
						let l = [
							{
								area:[],
								color: '#1890ff',
								data:[],
								index: 0,
								legendShape:"line",
								name: " ",
								pointShape:"circle",
								show: true,
								type: 'line'
							}
						]
						l[0].data = res.data.data[0].data.slice(-5)
						LineA.series = l;
						
						_self.textarea = JSON.stringify(res.data.data.LineA);
						_self.showLineA("canvasLineA",LineA);
					},
					fail: () => {
						_self.tips="网络错误，小程序端请检查合法域名";
					},
				});
			},
			showLineA(canvasId,chartData){
				canvaLineA=new uCharts({
					$this:_self,
					canvasId: canvasId,
					type: 'line',
					fontSize:11,
					padding:[15,20,0,15],
					legend:{
						show:true,
						padding:5,
						lineHeight:11,
						margin:0,
					},
					dataLabel:true,
					dataPointShape:true,
					background:'#FFFFFF',
					pixelRatio:_self.pixelRatio,
					categories: chartData.categories,
					series: chartData.series,
					animation: true,
					xAxis: {
						type:'grid',
						gridColor:'#CCCCCC',
						gridType:'dash',
						dashLength:8,
			      boundaryGap:'justify'
					},
					yAxis: {
						gridType:'dash',
						gridColor:'#CCCCCC',
						dashLength:8,
						splitNumber:5,
						format:(val)=>{return val.toFixed(0)}
					},
					width: _self.cWidth*_self.pixelRatio,
					height: _self.cHeight*_self.pixelRatio,
					extra: {
						line:{
							type: 'curve'
						}
					}
				});
				//下面是默认选中索引
				let cindex=3;
				//下面是自定义文案
				let textList=[{text:'最新报道',color:null},{text:'算力曲线',color:'#1890ff'}];
				//下面是event的模拟,tooltip的Y坐标值通过这个mp.changedTouches[0].y控制
				let tmpevent={mp:{changedTouches:[{x: 0, y: 80}]}};
				setTimeout(()=>{
					canvaLineA.showToolTip( tmpevent , {
						index:cindex,
						textList:textList
					});
				},200)
			},
			touchLineA(e) {
				canvaLineA.touchLegend(e);
				canvaLineA.showToolTip(e, {
					format: function (item, category) {
						return category + ' ' + item.name + ':' + item.data 
					}
				});
			},
			changeData(){
				if(isJSON(_self.textarea)){
					let newdata=JSON.parse(_self.textarea);
					canvaLineA.updateData({
						series: newdata.series,
						categories: newdata.categories
					});
				}else{
					uni.showToast({
						title:'数据格式错误',
						image:'../../../static/images/alert-warning.png'
					})
				}
			},
			touchCandle(e){
				canvaCandle.scrollStart(e);
			},
			moveCandle(e) {
				canvaCandle.scroll(e);
			},
			touchEndCandle(e) {
				canvaCandle.scrollEnd(e);
				//下面是toolTip事件，如果滚动后不需要显示，可不填写
				canvaCandle.showToolTip(e, {
					format: function (item, category) {
						return category + ' ' + item.name + ':' + item.data 
					}
				});
			},
			tapButton(type){
				let step=5;
				if(type=='in'){
					_self.itemCount -= step;
					if(_self.itemCount<=5){
						_self.itemCount=5;
					}
				}else{
					_self.itemCount += step;
					if(_self.itemCount>=_self.sliderMax){
						_self.itemCount=_self.sliderMax;
					}
				}
				_self.zoomCandle(_self.itemCount);
			},
			sliderMove(e){
				_self.itemCount=e.detail.value;
				_self.zoomCandle(e.detail.value);
			},
			zoomCandle(val) {
				canvaCandle.zoom({
					itemCount: val
				});
			},
			//获取资产值信息
			getassets() {
				uni.request({
					url: 'http://mall.zhongzhengyicai.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.bz_exchange&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						this.wheel = res.data.wheel
						this.zichan_power = res.data.zichan_power
						this.s_exchange = res.data.s_exchange
						this.bz_release = res.data.bz_release
						this.bz = res.data.bz
						this.nzichan_power = res.data.nzichan_power
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getassets1() {
				uni.request({
					url: 'http://mall.zhongzhengyicai.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.bz_exchange.bz_exchange_list&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						this.list = res.data.result.list
					},
					fail: () => {},
					complete: () => {}
				});
			},
			tokxt() {
				uni.navigateTo({
					url:'kxt/kxt'
				})
			},
			getbuy() {
				uni.navigateTo({
					url:'buy'
				})
			},
			getsale() {
				uni.navigateTo({
					url:'sale'
				})
			},
			togetbuy(){
				uni.navigateTo({
					url:'getbuy'
				})
			},
			tozczdh() {
				uni.navigateTo({
					url:'zczdh'
				})
			},
			obtain() {
				uni.navigateTo({
					url:'obtain/obtain?type='+ 2
				})
			},
			getmorenews() {
				this.page++;//每触底一次 page +1
				if (this.loadingType !== 0) {//loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showNavigationBarLoading();//显示加载动画
				uni.request({
					url:'http://mall.zhongzhengyicai.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.tzz&app=' + this.page,
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: function(res) {
						if (res.data.tzz == '') {//没有数据
							this.loadingType = 2;
							uni.hideNavigationBarLoading();//关闭加载动画
							return;
						}
						// this.newsList = this.newsList.concat(res.data.tzz);//将数据拼接在一起
						this.loadingType = 0;//将loadingType归0重置
						uni.hideNavigationBarLoading();//关闭加载动画
					}
				});
			},
			// 第一次请求数据，刷新
			
			getnewsList() {
				// this.setTopAjax()
				this.loadingType = 0;
				uni.showNavigationBarLoading();
				uni.request({
					url: 'http://mall.zhongzhengyicai.com/app/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=member.tzz&app=1',
					method: 'POST',
					data: {'openid':this.openid},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success: res => { 
						this.page++;//得到数据之后page+1
						this.topres = res.data.leiji_tzz;
						this.newsList = res.data.tzz;
						uni.hideNavigationBarLoading();
						uni.stopPullDownRefresh();//得到数据后停止下拉刷新
					}
				});
			},
		},
	}
</script>
<style>
	.qiun-charts {
		width: 750upx;
		height: 500upx;
		background-color: #FFFFFF;
	}
	
	.charts {
		width: 750upx;
		height: 500upx;
		background-color: #FFFFFF;
	}
	.qiun-textarea{height: 300upx;}
.container {
	background-color: #fff;
}
.loading-text {
	margin: ;
	background-color: fff;
	display: flex;
}

.loading-text text:nth-child(1) {
	padding-left: 15upx;
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 26upx;
}
.loading-text text:nth-child(2) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 26upx;
}
.loading-text text:nth-child(3) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 26upx;
}
.loading-text text:nth-child(4) {
	border-bottom: 2upx solid rgb(243,243,243);
	background-color: #fff;
	flex: 1;
	text-align: center;
	font-size: 26upx;
}
.all_add {
	height: 80upx;
	text-align: center;
	line-height: 80upx;
	background-color: rgb(254,162,61);
	color: #fff;
}
.big-loading-text {
	font-weight: 550;
	border-bottom: 2upx solid rgb(243,243,243);
}
.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
uni-page-body{height:100%;}
</style>

